﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using IRepository;
using System;
using System.Collections.Generic;
using System.Data;
using MySql.Data.MySqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Model.Models;
using Model.Dto;

namespace Repository
{
    /// <summary>
    /// 用户仓储层实现类
    /// </summary>
    public class UserRepository : BaseRepository<User>, IUserRepository
    {
        #region  依赖注入数据访问层
        /// <summary>
        /// 依赖注入数据访问层
        /// </summary>
        /// <param name="gmdbContext"></param>
        public UserRepository(IgmdbContext gmdbContext) : base(gmdbContext)
        {

        }
        #endregion
        public async Task<int> ModifyByKey(User user)
        {
            // 查询要更新的实体

            User UserItem = base.Db.Users.Find(user.UserId);
            UserItem.UserCode = user.UserCode;
            UserItem.UserName = user.UserName;
            UserItem.Email = user.Email;
            UserItem.Mobile = user.Mobile;
            UserItem.Password = user.Password;
            UserItem.Avatar = user.Avatar;

            // 更新用户
            return await Db.SaveChangesAsync();
        }
    }
}
